enum SIZE {
    //% block="29*29"
    1,
    //% block="58*58"
    2
}

enum LINE {
    //% block="1"
    1,
    //% block="2"
    2,
    //% block="3"
    3,
    //% block="4"
    4
}

enum BTN {
    //% block="A"
    A,
    //% block="B"
    B,
    //% block="A+B"
    AB
}

//% color="#AA278D" iconWidth=50 iconHeight=40
namespace l9110s {
     //% block="L9110S/DRV8833-电机 速度管脚[PIN_AnalogWrite] 方向管脚[PIN_DigitalWrite] 速度(-255~255)[SPEED]" blockType="command"
    //% PIN_AnalogWrite.shadow="dropdown" PIN_AnalogWrite.options="PIN_AnalogWrite"  PIN_AnalogWrite.defl="PIN_AnalogWrite.1"
    //% PIN_DigitalWrite.shadow="dropdown" PIN_DigitalWrite.options="PIN_DigitalWrite"  PIN_DigitalWrite.defl="PIN_DigitalWrite.1"
    //% SPEED.shadow="number" SPEED.defl=255
    export function Motor(parameter: any, block: any) {
        let speedpin = parameter.PIN_AnalogWrite.code
        let dirpin = parameter.PIN_DigitalWrite.code
        let speed = parameter.SPEED.code
        //Generator.addInclude('l9110s', ' ');
        Generator.addObject(`l9110s`, ` `, `void setMotor(int speedpin,int dirpin, int speed)\n\t
   {
        if (speed == 0)
        {
            digitalWrite(dirpin, LOW);
            digitalWrite(speedpin, LOW);
            //analogWrite(speedpin, 0);
        }
        else if (speed > 0)
        {
            digitalWrite(dirpin, LOW);
            analogWrite(speedpin, speed);
        }
        else
        {   
            if (speed < -255){ speed = -255; }
            digitalWrite(dirpin, HIGH);
            analogWrite(speedpin,255+speed);
        }
}`);
        Generator.addSetup(`L9110s_${speedpin}.begin`, 
 `pinMode(${speedpin}, OUTPUT);
  pinMode(${dirpin}, OUTPUT);
  digitalWrite(${speedpin}, LOW);
  digitalWrite(${dirpin}, LOW);`);
        Generator.addCode(`setMotor(${speedpin}, ${dirpin},${speed});`);
    }



}
